package com.bilin.coin.activity;

import android.view.View;
import android.widget.LinearLayout;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.bilin.coin.R;
import com.bilin.coin.bean.CoinBean;
import com.bilin.coin.bean.CoinRecordBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.list.RechargeWithdrawRecordList;
import com.bilin.coin.tools.AlertUtils;
import com.bilin.coin.tools.Poster;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;


@Route(path = "/order/RechargeWithdrawCoinRecordActivity")
public class RechargeWithdrawCoinRecordActivity extends BaseAppCompatActivity {

    @BindView(R.id.ll_main)
    LinearLayout ll_main;

    @Autowired
    CoinBean coinBean;

    RechargeWithdrawRecordList recordList;

    @Autowired
    int type;//0充1提
    private BaseQuickAdapter baseQuickAdapter;

    @Override
    protected void initView() {
        if (type == 0) {
            setTitle("充"+coinBean.getName()+"纪录");
        } else {
            setTitle("提"+coinBean.getName()+"纪录");
        }
        recordList = new RechargeWithdrawRecordList(this,type,coinBean.getId(),coinBean.getName());
        ll_main.addView(recordList.getRootView());
        recordList.refresh(true);
        baseQuickAdapter = recordList.obtainAdapter();
        baseQuickAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                CoinRecordBean.RecordsBean item = (CoinRecordBean.RecordsBean) adapter.getData().get(position);
                AlertUtils.dialog(RechargeWithdrawCoinRecordActivity.this, "提示", "确定取消吗？", new AlertUtils.OnPositiveClick() {
                    @Override
                    public void onClick() {
                        cancel(item, position);
                    }
                });
            }
        });
        if (type == 1) {
            baseQuickAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    CoinRecordBean.RecordsBean item = (CoinRecordBean.RecordsBean) adapter.getData().get(position);
                    baseStartActivityWith("/order/WithdrawCoinDetailActivity")
                            .withParcelable("item",item)
                            .withString("coinName",coinBean.getName())
                            .navigation();
                }
            });
        }
    }
    private void cancel(CoinRecordBean.RecordsBean item, int position) {
        new Poster(this) {
            @Override
            protected String fillUrl() {
                return "/api/coin/cancelWithdraw";
            }

            @Override
            protected Map<String, String> fillParams() {
                HashMap map = new HashMap();
                map.put("id",item.getId()+"");
                return map;
            }

            @Override
            protected void disposeSuccess(String dataJson) {
                super.disposeSuccess(dataJson);
                baseQuickAdapter.remove(position);
            }
        };
    }
    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_common;
    }
}
